package com.googlecode.perfectable.persistable.session;

import javax.annotation.Nullable;

import com.google.common.base.Objects;

public class StringIdentifier<T> implements Identifier<T> {
	private static final long serialVersionUID = 2324871452276600536L;

	private final String code;

	public static <X> StringIdentifier<X> of(String code) {
		return new StringIdentifier<>(code);
	}

	private StringIdentifier(String code) {
		this.code = code;
	}

	@Override
	public String code() {
		return this.code;
	}

	@Override
	public boolean equals(@Nullable Object obj) {
		if(this == obj) {
			return true;
		}
		if(!(obj instanceof StringIdentifier)) {
			return false;
		}
		StringIdentifier<?> other = (StringIdentifier<?>) obj;
		return Objects.equal(this.code, other.code);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.code);
	}

}
